﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sinacor.Infra.Service.Data;
using Sinacor.Infra.Service.Security.Authorization;
using System.Data.Common;

namespace Sinacor.Servico.Bovespa.Parametro.ResourceAccess
{
    public class ConfiguracaoOMM: BaseResourceAccess
    {

        #region Constructor

        /// <summary>
        /// Construtor padrão
        /// </summary>
        public ConfiguracaoOMM()
            : base(AuthorizationContext.Current.CompanyId)
        { }

        #endregion

        #region Métodos

        /// <summary>
        /// Obtém as configurações necessárias para se conectar ao serviço de monitoração da saúde do sistema
        /// OMM (Order Message Manager)
        /// </summary>
        /// <returns></returns>
        public BusinessEntity.MonitorOMMConfiguracaoCliente ObterMonitorOMMConfiguracaoCliente()
        {
            //
            BusinessEntity.MonitorOMMConfiguracaoCliente configuracao;
            String sqlCommand = String.Empty;

            //
            sqlCommand = @"SELECT NUM_PRTA_TCP,
                                  NOME_SERD_TCP
                           FROM TBOCNFG_MONC_SIST";

            using (DbCommand dbCommand = this.DataBase.GetSqlStringCommand(sqlCommand))
            {
                configuracao = this.FindOne<BusinessEntity.MonitorOMMConfiguracaoCliente>(dbCommand,
                    reader =>
                    {
                        //
                        BusinessEntity.MonitorOMMConfiguracaoCliente retorno = new BusinessEntity.MonitorOMMConfiguracaoCliente();
                        //
                        retorno.TcpServerPort = reader.GetValue<Int32>("NUM_PRTA_TCP");
                        retorno.TcpServerHostName = reader.GetValue<String>("NOME_SERD_TCP");
                        //
                        return retorno;
                    });
            }

            return configuracao;
        
        }

        #endregion

    }
}
